package com.spzx.product.api.factory;

import com.spzx.product.api.RemoteProductService;
import com.spzx.common.core.domain.R;
import com.spzx.product.domain.ProductSkuVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    //专门记录某个类的日志
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);
    @Override
    public RemoteProductService create(Throwable throwable) {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new RemoteProductService() {
            //实现降级逻辑,快速返回失败消息
            public R<ProductSkuVo> getProductSku(Long skuId, String source) {
                return R.fail("获取商品sku失败:" + throwable.getMessage());
            }
        };
    }
}
